package com.markrfield.iRacingTelemetryView;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;
import android.os.Handler;
import android.util.Log;

public class ServerThread implements Runnable {
	
	private Handler handler = new Handler();
	
	public void run() {
							
		handler.post(new Runnable() {

			public void run() {
				
				// ServerSocket
				ServerSocket ss = null;
				
				try {
					// Create new ServerSocket, listening on specified port
					ss = new ServerSocket(8080);
															
					while(true) {
						// Accept a new client
						Socket s = ss.accept();
						
						// Create a new buffered reader
						BufferedReader br = new BufferedReader(new InputStreamReader(s.getInputStream()));
						
						// Read line
						System.out.println(br.readLine());
						
						// Close BufferedReader and Socket.
						br.close();
						s.close();
					}
					
					
				} catch (IOException e) {
					e.printStackTrace();
					Log.w("iRacing", "Error");
				}
								
			}
			
		});
					
	}
		
}